using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using SoapValidation;

namespace Tests
{
	// these namespace bindings are used to process the XPath assertions 
	// used below in the Assert attribute declarations
	[AssertNamespaceBinding("s", "http://schemas.xmlsoap.org/soap/envelope/")]
	[AssertNamespaceBinding("t", "http://example.org/geometry")]
	// this assertion applies to all WebMethods below
	[Assert(@"//t:width >= 0", "width must be greater than 0")]
	[WebService(Namespace="http://example.org/geometry")]
	[SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)]
	public class SimpleTests : System.Web.Services.WebService
	{	
		// this method performs schema validation and checks assertions
		// (only class assertions apply since none are declared here)
		[WebMethod]
		[Validation]
		public double CalcArea1(double length, double width)
		{
			return length * width;
		}	

		// this method performs schema validation and checks assertions
		[WebMethod]
		[Validation]
		[Assert("/s:Envelope/s:Body/t:CalcArea2/t:length > /s:Envelope/s:Body/t:CalcArea2/t:width", 
			 "Length must be greater than or equal to width")]
		[Assert("(//t:length * //t:width) > 100", "Area must be greater than 100")]
		[Assert("(//t:length div //t:width) = 2", "Length must be exactly twice width")]
		public double CalcArea2(double length, double width)
		{
			return length * width;
		}	

		// this method only checks assertions (no schema validation)
		[WebMethod]
		[Validation(SchemaValidation=false)]
		[Assert("/s:Envelope/s:Body/t:CalcArea3/t:length > /s:Envelope/s:Body/t:CalcArea3/t:width", 
			 "Length must be greater than or equal to width")]
		public double CalcArea3(double length, double width)
		{
			return length * width;
		}	

		// this method only performs schema validation (no assertions)
		[WebMethod]
		[Validation(CheckAssertions=false)]
		[Assert("/s:Envelope/s:Body/t:CalcArea4/t:length > /s:Envelope/s:Body/t:CalcArea4/t:width", 
			 "Length must be greater than or equal to width")]
		public double CalcArea4(double length, double width)
		{
			return length * width;
		}	

		// this method disables all forms of validation
		[WebMethod]
		[Validation(SchemaValidation=false, CheckAssertions=false)]
		[Assert("/s:Envelope/s:Body/t:CalcArea5/t:length > /s:Envelope/s:Body/t:CalcArea5/t:width", 
			 "Length must be greater than or equal to width")]
		public double CalcArea5(double length, double width)
		{
			return length * width;
		}	
	
	}
}
